/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       town_window.h

	$Header: /game/town.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef TOWN_WINDOW_H_INCLUDED
#define TOWN_WINDOW_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#pragma warning( disable: 4786 )

#include <map>
#include <set>
#include "army_ptr.h"
#include "bitmap_group_array.h"
#include "bitmap_layer_window_ptr.h"
#include "bitmap_layer_cache_window_ptr.h"
#include "blended_bitmap_window_ptr.h"
#include "button_ptr.h"
#include "creature_array_window_ptr.h"
#include "creature_detail_display.h"
#include "game_window.h"
#include "map_point.h"
#include "material_display.h"
#include "text_window_ptr.h"
#include "toggle_button_ptr.h"
#include "town.h"
#include "town_building_set.h"

class t_adventure_frame;
class t_button;
enum  t_creature_type;
class t_garrison_button;
class t_idle_processor;
class t_progress_handler;
class t_town_list_window;

class t_town_window : public t_window
{
public:
	struct t_dwelling_icon
	{
		t_bitmap_layer_cache_window_ptr portrait;
		t_creature_type                 creature;
		t_button*                       button;
		t_window_ptr				    inset;
		t_text_window_ptr				text;
	};

	t_town_window( t_town* town, t_army* adjacent_army, t_adventure_frame* parent );
	virtual ~t_town_window();
	
	void cancel_divide_mode();
	void do_fade();
	t_army_ptr get_trading_army( t_town * town );
	void set_trading_army( t_town * town, t_army_ptr army );
	virtual bool menu_click( int id );
	void trigger_temporary_army_events();
	void update_creature_windows();
	void update_materials();
	void update_nobility_display();

	// public so can safety check towns from having too many dwellings
	enum
	{
		k_dwelling_icon_count = 6
	};

protected:
	bool			add_animation( t_town_building building );
	void			blacksmith( t_button* );
	void			build_all();
	void			build_ship( t_button* );
	void			buy_building( t_button* button );
	void			buy_creatures( t_button* button, t_creature_type creature_type );
	void			caravan_create();
	void			caravan_handle_arrivals();
	void			caravan_view();
	void			castle( t_button* );
	void			check_for_grail();
	void			choose_lord();
	void			close_click( t_button* button );
	void			close_garrison_window();
	void			create_army();
	void			create_building_image( t_town_building building, int layout_bottom );
	void			create_building_windows();
	void			create_buildings();
	void			create_buttons();
	void			create_creature_detail();
	void			create_dwelling_icons();
	void			create_garrison_window();
	void			creature_double_click( t_creature_array_window* window, int slot );
	void			creature_portal_click( t_button* );
	void			describe_building(t_button *button, t_town_building building);
	void			describe_treasury(t_button *button );
	void			display_caravan_window();
	void			display_growth_breakdown_window(t_button *button, t_town_building building);
	void			divide_clicked( t_button* button );
	void			enter_town();
	void			fade_in( t_town_building building, bool fast );
	t_screen_point	get_interface_origin() const;
	int				get_load_time( t_town* town );
	int				get_recruitment_discount() const;
	void			hire_hero( t_button* );
	bool			player_owns_town() const;
	void			mage_guild( t_button* );
	void			mana_vortex( t_button* );
	void			marketplace();
	void			menu_buy_building();
	void			move_down_click( t_button* );
	void			move_up_click( t_button* );
	virtual void    on_close();
    void            prison( t_button* );
	void			seminary( t_button* );
	void			set_detail_mode( bool arg );
	void			set_dwelling_icons();
	void			set_town( t_town* town );
	void			set_new_town( t_town* town, t_progress_handler* progress_handler );
	void			setup_temp_army();
	void			show_icon_detail( t_button* button );
	void			show_text_detail( t_button* button );
    void            skeleton_transformer( t_button* );
	void			town_menu( t_button* button );
	void			university( t_button* );

	typedef std::set< t_town_building> t_set;
	typedef std::map< t_town*, t_army_ptr> t_army_map;
	typedef std::set< t_town * > t_town_set;

	t_army_ptr					m_adjacent_army;
	t_adventure_frame*			m_adventure_frame;
	t_bitmap_group_array		m_animations;
	t_idle_processor*			m_animator;
	t_window_ptr				m_building_animation[k_town_building_count];
	t_button_ptr				m_building_button[k_town_building_count];
	t_bitmap_window_ptr			m_building_highlight[k_town_building_count];
	t_blended_bitmap_window_ptr	m_building_shadow[k_town_building_count];
	t_blended_bitmap_window_ptr	m_building_window[k_town_building_count];
	t_town_set					m_checked_grail_towns;
	t_creature_detail_display   m_creature_detail;
	t_window*                   m_creature_icon_detail;
	t_window*                   m_creature_text_detail;
	t_town_building_set			m_drawn_buildings;
	t_dwelling_icon				m_dwelling_icons[k_dwelling_icon_count]; 
	t_creature_array_window_ptr	m_garrison_window;
	t_window_ptr				m_highlight_animation[k_town_building_count];
	t_bitmap_group_ptr			m_highlight_layout;
	t_set						m_fading_in;
	t_set						m_fading_out;
	t_bitmap_group_ptr			m_interface;
	t_window*					m_interface_window;
	bool						m_keyboard_on_visitor;
	t_bitmap_group_ptr			m_layout;
	t_bitmap_window_ptr			m_lord_border;
	t_button_ptr				m_lord_button;
	t_bitmap_window_ptr			m_lord_portrait;
	t_material_display			m_material_display;
	t_button_ptr				m_move_down_button;
	t_button_ptr				m_move_up_button;
	t_bitmap_group_ptr			m_rings;
	bool                        m_showing_text_detail;
	t_window_ptr				m_single_border;
	t_toggle_button_ptr			m_split_button;
	t_army_ptr					m_temp_army;
	t_bitmap_group_ptr			m_terrain;
	t_bitmap_window_ptr			m_terrain_background;
	t_window_list				m_terrain_foreground;
	t_town*						m_town;
	t_town_list_window*			m_town_list;
	t_text_window_ptr			m_town_name;
	t_army_map					m_trading_armies;
	t_creature_array_window_ptr	m_visitor_window;
};


bool check_garrison_space( t_town* town, t_creature_type creature_type );


#endif // TOWN_WINDOW_H_INCLUDED
